package com.Exception;

import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
public class ExceptionDemo2 {
    public static void main(String[] args) {
        method1();
        method2();
    }
    //编译时异常:
    //不等于有异常，可能会有异常，需要对代码进行处理
    public static void method1(){
        try {
            String s = "2022-03-23";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date d = sdf.parse(s);
            System.out.println(d);
        }catch(ParseException pe){
            pe.printStackTrace();
        }
    }
    //运行时异常
    public static void method2() {
        try {
            int[] arr = {1, 2, 3, 4};
            System.out.println(arr[4]);
        }catch(ArrayIndexOutOfBoundsException ae){
            ae.printStackTrace();
        }
    }
}
